package edu.umn.se.trap.logicChecker;

import java.util.Observable;
import java.util.Observer;
import java.util.Vector;

import edu.umn.se.trap.Form;
import edu.umn.se.trap.exceptions.TrapException;
import edu.umn.se.trap.Transportation;

public class CheckLogicAirDomestic implements Observer {
    
    @Override
    /**
     * Update for checking logic on air domestic transportation
     */
    public void update(Observable o, Object arg) 
    {
        LogicChecker l1 = (LogicChecker) o;
        Form form = (Form) arg;
        
        Vector<Transportation> transportVec = form.getTransportation();
        
        for (int i = 0; i < transportVec.size(); i++)
        {
            Transportation transport = transportVec.elementAt(i);
            if (transport.getType().equalsIgnoreCase("air"))
            {
                if (!transport.getCarrier().equalsIgnoreCase("Southwest") &&
                        !transport.getCarrier().equalsIgnoreCase("Alaska Airlines") &&
                        !transport.getCarrier().equalsIgnoreCase("American") &&
                        !transport.getCarrier().equalsIgnoreCase("Delta") &&
                        !transport.getCarrier().equalsIgnoreCase("Frontier") &&
                        !transport.getCarrier().equalsIgnoreCase("Great Lakes") &&
                        !transport.getCarrier().equalsIgnoreCase("Spirit") &&
                        !transport.getCarrier().equalsIgnoreCase("Sun County") &&
                        !transport.getCarrier().equalsIgnoreCase("United") &&
                        !transport.getCarrier().equalsIgnoreCase("US Airways"))
                {
                    l1.setException(new TrapException("Air carrier must be domestic")); 
                }
            }
        }      
    }
}